//////////////////////////////////////////////////////
//Main.cpp
//////////////////////////////////////////////////////
#include "tipos.h"
#include "Ajuste.h"
#include "Euler.h"
#include "Interpolado.h"
#include "RungeKutta21.h"
#include "RungeKutta4.h"
#include "iPrima.h"
#include "qPrimaPos.h"
#include "qPrimaNeg.h"
#include <iostream>
double et(ptoF t){
	return (exp (t) - exp (-t))/(exp(t) + exp(-t));
}
double etPrima(ptoF t){
	return 2/(exp(t) + exp(-t));
}

/////
//		RungeKutta			//
//////////////////////////////////////////////////
int main(int argc,char** argv){
	if(argc != 4){
		std::cout << "parametros: <paso> <corte> <funcion:(i,q+,q-)>" << std::endl;
		exit(1);
	}
	ptoF paso=atof(argv[1]);
	ptoF stop=atof(argv[2]);
	Funcion* iprima=NULL;//= new iPrima(paso);
	Metodo* euler;
	Metodo* rk2;
	Metodo* rk4;
	if(strcmp(argv[3],"i")==0){
		iprima=new iPrima(paso);
	}else if(strcmp(argv[3],"q+")==0){
		iprima=new qPrimaPos(paso);
	}else if(strcmp(argv[3],"q-")==0){
		iprima=new qPrimaNeg(paso);
	}
	euler=new Euler(paso,iprima,0);
	rk2= new RungeKutta2(paso,iprima,0);
	rk4= new RungeKutta4(paso,iprima,0);

	
	//Euler* euler=new Euler(2*86400,derivada,34046680,"c:/resul_ajuste.txt");
	//Euler* euler=new Euler(5*86400,derivada,33554200,"c:/resul_ajuste.txt");
	//Euler* euler=new Euler(10*86400,derivada,32733400,"c:/resul_ajuste.txt");
	std::cout << "Tiempo: ;\tEuler;\tRungeKutta2;\tRungeKutta4\n";
	try{
		float t=0;
		ptoF e,r1,r2=0;
		while(t<stop){
			e=euler->iterar();
			r1=rk2->iterar();
			r2=rk4->iterar();
			std::cout << t << ";\t" << e << ";\t" << r1 << ";\t" << r2 << "\n";
			t+=paso;
			//std::cout << aux << std::endl;
		}
	}
	catch(...){
		//atrapa el eof
	}
	delete iprima;
	delete euler;
	delete rk2;
	delete rk4;
	return 0;
}
